﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMTP.Master" AutoEventWireup="true" CodeBehind="StudentFee.aspx.cs" Inherits="SQT.tracnghiem.Admin.StudentFee" %>

<%@ Import Namespace="DataAccess" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Ajax/JS/Accountant.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="main-admin" class="admin-df w3-row w3-light-grey">
        <header class="w3-padding w3-large w3-center w3-teal">KẾ TOÁN&nbsp;<i class="fa fa-angle-right"></i>&nbsp;HỌC PHÍ</header>
        <div id="ac2" class="acc w3-row">
            <div class="w3-col l7">
                <div class="w3-row w3-padding">
                    <select id="filter-option" class="accountant-select w3-teal">
                        <option value="0" selected="selected">Theo tháng</option>
                        <option value="1">Theo mã HV</option>
                    </select>
                    <select id="filter-class" class="accountant-select">
                        <option value="0">Tất cả lớp</option>
                        <%
                            var get_class = (from p in new TblClassController().FetchAll().Where(x => x.Active == true && x.Id != 0) orderby p.Id descending select p);
                            foreach (TblClass tbl_class in get_class)
                            {%>
                        <option value="<%=tbl_class.Id %>"><%=tbl_class.ClassName %></option>
                        <%;
                            } %>
                    </select>
                    <select class="accountant-select" id="bill_month">
                        <%for (int i = 1; i <= 12; i++)
                          { %>
                        <%if (i == DateTime.Now.Month)
                          { %>
                        <option selected="selected" value="<%=i %>"><%=i %></option>
                        <%}
                          else
                          { %>
                        <option value="<%=i %>"><%=i %></option>
                        <%} %>

                        <%} %>
                    </select>
                    <select class="accountant-select" id="bill_year">
                        <%for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 8; i--)
                          { %>
                        <option value="<%=i %>"><%=i %></option>
                        <%} %>
                    </select>
                    <input class="accountant-code" id="find_member" type="text" placeholder="Nhập mã hv" />
                    <a id="btn_study_search" class="w3-btn w3-teal" title="Tra cứu" style=""><i class="fa fa-search"></i></a>
                    <a class="study-pay-btn w3-btn w3-teal" title="Đóng học phí" style=""><i class="fa fa-plus"></i>&nbsp;Đóng học phí</a>
                    <a class="save-pay-btn w3-btn w3-teal" title="Bảo lưu học phí" style=""><i class="fa fa-download"></i>&nbsp;Bảo lưu</a>
                    <a onclick="$('#fee-modal').fadeIn()" class="fee-btn w3-btn w3-teal" title="Quản lý học phí" style=""><i class="fa fa-money"></i>&nbsp;QL</a>
                    <div id="study-pay-modal" class="w3-modal">
                        <div class="study-pay-modal w3-modal-content w3-card-8 w3-animate-top" style="width: 45%">
                            <header class="w3-padding w3-center w3-teal">
                                <i class="fa fa-times w3-closebtn w3-hover-text-white" onclick="$('#study-pay-modal').fadeOut()"></i>
                                <span class="w3-large">ĐÓNG HỌC PHÍ</span>
                            </header>
                            <div class="w3-row w3-padding">
                                <div class="w3-row w3-padding-bottom">
                                    <span class="w3-col l3">Mã HV</span>
                                    <input id="study_number" style="text-transform: uppercase" class="w3-half w3-border w3-border-teal" type="text" placeholder="Nhập mã học viên" />
                                    <a onclick="document.getElementById('student-detail').style.display = 'block'" class="check_number w3-btn w3-teal hvr-icon-forward w3-col l3">Kiểm tra</a>
                                </div>
                                <div id="student-detail">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="save-pay-modal" class="w3-modal">
                        <div class="study-pay-modal w3-modal-content w3-card-8 w3-animate-top" style="width: 45%">
                            <header class="w3-padding w3-center w3-teal">
                                <i class="fa fa-times w3-closebtn w3-hover-text-white" onclick="$('#save-pay-modal').fadeOut()"></i>
                                <span class="w3-large">BẢO LƯU HỌC PHÍ</span>
                            </header>
                            <div class="w3-row w3-padding">
                                <div class="w3-row w3-padding-bottom">
                                    <span class="w3-col l3">Mã HV</span>
                                    <input id="study_number2" style="text-transform: uppercase" class="w3-half w3-border w3-border-teal" type="text" placeholder="Nhập mã học viên" />
                                    <a onclick="document.getElementById('student-detail2').style.display = 'block'" id="btn_Save_Fee" class="w3-btn w3-teal hvr-icon-forward w3-col l3">Kiểm tra</a>
                                </div>
                                <div id="student-detail2">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="edit-study-pay-modal" class="w3-modal">
                        <div class="study-pay-modal w3-modal-content w3-card-8 w3-animate-bottom" style="width: 45%">
                            <header class="w3-padding w3-center w3-teal">
                                <i class="fa fa-times w3-closebtn w3-hover-text-white" onclick="document.getElementById('edit-study-pay-modal').style.display = 'none'"></i>
                                <span class="w3-large">SỬA HỌC PHÍ</span>
                            </header>
                            <div id="edit_bill_area" class="w3-row w3-padding">
                            </div>
                        </div>
                    </div>
                    <div id="delete-study-pay-modal" class="w3-modal">
                        <div id="del_bill_id" class="w3-hide"></div>
                        <div class="study-pay-modal w3-modal-content w3-card-8 w3-animate-bottom w3-teal" style="width: 38%">
                            <header class="w3-padding w3-center">
                                <span class="w3-large">Bạn có chắc chắn muốn xóa hóa đơn này ?</span>
                            </header>
                            <div class="w3-row w3-padding w3-center">
                                <a id="btn_del_bill" class="w3-btn w3-teal w3-border"><i class="fa fa-check"></i>&nbsp;Xác nhận</a>&nbsp;
                                <a onclick="document.getElementById('delete-study-pay-modal').style.display = 'none'" class="w3-btn w3-teal w3-border"><i class="fa fa-times"></i>&nbsp;Hủy</a>
                            </div>
                        </div>
                    </div>
                    <div id="fee-modal" class="w3-modal">
                        <div class="fee-modal w3-modal-content w3-card-8 w3-animate-top" style="">
                            <table class="w3-table w3-white w3-striped w3-card-2">
                                <thead>
                                    <tr class="w3-teal">
                                        <th>Hình thức</th>
                                        <th>Gói</th>
                                        <th>Học phí</th>
                                        <th>Ưu đãi</th>
                                        <th>Tùy chọn</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>
                                            <input style="width: 150px" type="text" placeholder="Nhập hình thức" value="Du học" /></td>
                                        <td>
                                            <input style="width: 100px" type="text" placeholder="Nhập gói" value="1 Tháng" /></td>
                                        <td>
                                            <input style="width: 160px" type="text" placeholder="Nhập học phí" value="250,000 vnđ" /></td>
                                        <td>
                                            <input style="width: 150px" type="text" placeholder="Nhập ưu đãi (nếu có)" value="0%" /></td>
                                        <td><i class="fee-option-btn fa fa-save" title="Lưu"></i><i class="fee-option-btn fa fa-times" title="Hủy"></i></td>
                                    </tr>
                                    <tr>
                                        <td>Phổ Thông</td>
                                        <td>2 Tháng</td>
                                        <td>480,000 vnđ</td>
                                        <td>Tiết kiệm 10%</td>
                                        <td><i class="fee-option-btn fa fa-edit" title="Chỉnh sửa"></i><i class="fee-option-btn fa fa-trash" title="Xóa"></i></td>
                                    </tr>
                                    <tr>
                                        <td>Ban đêm</td>
                                        <td>3 Tháng</td>
                                        <td>700,000 vnđ</td>
                                        <td>Tiết kiệm 15%</td>
                                        <td><i class="fee-option-btn fa fa-edit" title="Chỉnh sửa"></i><i class="fee-option-btn fa fa-trash" title="Xóa"></i></td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input style="width: 150px" type="text" placeholder="Nhập hình thức" /></td>
                                        <td>
                                            <input style="width: 100px" type="text" placeholder="Nhập gói" /></td>
                                        <td>
                                            <input style="width: 160px" type="text" placeholder="Nhập học phí" /></td>
                                        <td>
                                            <input style="width: 150px" type="text" placeholder="Nhập ưu đãi (nếu có)" /></td>
                                        <td><i class="fee-option-btn fa fa-save" title="Lưu"></i><i class="fee-option-btn fa fa-times" title="Hủy"></i></td>
                                    </tr>
                                    <tr>
                                        <td colspan="5" class="w3-center">
                                            <a class="add-fee-btn w3-btn w3-teal" title="Thêm mức học phí" style=""><i class="fa fa-plus"></i>&nbsp;Thêm mức học phí</a>
                                            <a onclick="$('#fee-modal').fadeOut()" class="w3-btn w3-teal" title="Hủy" style=""><i class="fa fa-times"></i>&nbsp;Hủy</a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <% %>
                <div class="accountant-table w3-row w3-padding w3-responsive">
                    <table class="w3-table w3-striped w3-white w3-bordered w3-card-2" id="check_bill_area">
                        <thead>
                            <tr class="w3-teal">
                                <th>Mã HV</th>
                                <th>Họ tên</th>
                                <th>Lớp</th>
                                <th>Học phí</th>
                                <th>Gói</th>
                                <th>Ngày đóng</th>
                                <th>Ngày hết hạn</th>
                            </tr>
                        </thead>
                        <%
                            for (int i = 0; i <= 31; i += 7)
                            {
                        %>
                        <tr>
                            <td colspan="7" class="w3-center w3-text-teal">- Tuần <%=i / 7 + 1%> -</td>
                        </tr>
                        <%
                                var get_user = from p in new TblStudyFeeController().FetchAll() where p.Active == true && DateTime.Parse(p.PayDate.ToString()).Day > i && DateTime.Parse(p.PayDate.ToString()).Day <= i + 7 && DateTime.Parse(p.PayDate.ToString()).Month == DateTime.Now.Month && DateTime.Parse(p.PayDate.ToString()).Year == DateTime.Now.Year orderby p.Id descending select p;
                                foreach (TblStudyFee fee in get_user)
                                {
                                    var get_member = new TblUserController().FetchAll().Where(x => x.UserId == fee.UserId).Single();
                                    var get_cls = new TblClassController().FetchAll().Where(x => x.Id == get_member.ClassX).Single();
                        %>
                        <tr class="bill" id="bill<%=fee.Id%>" style="cursor: pointer">
                            <td class="bill_id w3-hide"><%=fee.Id%></td>
                            <td><%=get_member.NumberStudy%></td>
                            <td><%=get_member.FullName%></td>
                            <td><%=get_cls.ClassName%></td>
                            <td><%=fee.Fee%></td>
                            <td><%=fee.Packet%> tháng</td>
                            <td><%=DateTime.Parse(fee.PayDate.ToString()).Day%>/<%=DateTime.Parse(fee.PayDate.ToString()).Month%>/<%=DateTime.Parse(fee.PayDate.ToString()).Year%></td>
                            <td><%=DateTime.Parse(fee.ExpDate.ToString()).Day%>/<%=DateTime.Parse(fee.ExpDate.ToString()).Month%>/<%=DateTime.Parse(fee.ExpDate.ToString()).Year%></td>
                        </tr>
                        <%}
                            } %>
                    </table>
                </div>
            </div>
            <div class="w3-col l5 w3-padding-top w3-padding-right w3-padding-bottom">
                <div class="w3-white w3-card-2">
                    <header class="w3-padding w3-center w3-teal">
                        THỜI HẠN HỌC PHÍ CỦA
                        <select id="filter_class" class="w3-teal w3-border" style="outline: none">
                            <option value="0">Tất cả lớp</option>
                            <%
                                foreach (TblClass cls in get_class)
                                { %>
                            <option value="<%=cls.Id %>"><%=cls.ClassName %></option>
                            <%} %>
                        </select>
                    </header>
                    <ul class="w3-ul">
                        <li class="w3-padding w3-row w3-light-grey">
                            <div class="w3-col l2">
                                <span>Mã HV</span>
                            </div>
                            <div class="w3-col l5">
                                <span>Họ tên</span>
                            </div>
                            <div class="w3-col l3">
                                <span>Lớp</span>
                            </div>
                            <div class="w3-col l2">
                                <span>Thời hạn</span>
                            </div>
                        </li>
                    </ul>
                    <ul id="study_fee_area" class="study-fee w3-ul">
                        <%foreach (TblClass cls in get_class)
                          { %>
                        <%var get_user = new TblUserController().FetchAll().Where(x => x.ClassX == cls.Id);
                          foreach (TblUser user in get_user)
                          {
                              var get_user_bill = new TblStudyFeeController().FetchAll().Where(x => x.UserId == user.UserId).ToList();
                              if (get_user_bill.Count != 0)
                              {
                                  var get_bill = new TblStudyFeeController().FetchAll().Where(x => x.UserId == user.UserId && x.Active == true).Last();
                                  DateTime now = DateTime.Now;
                                  DateTime exp = DateTime.Parse(get_bill.ExpDate.ToString());
                                  TimeSpan remain = exp.Subtract(now);
                                  int day = remain.Days;
                                  if (day > 0)
                                      day++;      
                        %>
                        <li class="w3-padding w3-row">
                            <div class="w3-col l2">
                                <%if (!string.IsNullOrEmpty(user.NumberStudy))
                                  { %>
                                <span><%=user.NumberStudy %></span>
                                <%}
                                  else
                                  { %>
                                <span>&nbsp;</span>
                                <%} %>
                            </div>
                            <div class="w3-col l5">
                                <span><%=user.FullName%></span>
                            </div>
                            <div class="w3-col l3">
                                <span><%=cls.ClassName%></span>
                            </div>
                            <%if (day > 14)
                              {%>
                            <div class="w3-col l2">
                                <span class=" w3-text-teal"><i class="fa fa-thumbs-o-up"></i>&nbsp;<%=day%> ngày</span>
                            </div>
                            <%}
                              else
                              { %>
                            <%if (day >= 7 && day <= 14)
                              { %>
                            <div class="w3-col l2">
                                <span class=" w3-text-orange"><i class="fa fa-exclamation-triangle"></i>&nbsp;<%=day%> ngày</span>
                            </div>
                            <%}
                              else
                              { %>
                            <div class="w3-col l2">
                                <span class=" w3-text-red"><i class="fa fa-times-circle"></i>&nbsp;<%=day%> ngày</span>
                            </div>
                            <%}
                              } %>
                        </li>
                        <%
                              }
                              else
                              {
                        %>
                        <li class="w3-padding w3-row">
                            <div class="w3-col l2">
                                <%if (!string.IsNullOrEmpty(user.NumberStudy))
                                  { %>
                                <span><%=user.NumberStudy %></span>
                                <%}
                                  else
                                  { %>
                                <span>&nbsp;</span>
                                <%} %>
                            </div>
                            <div class="w3-col l5">
                                <span><%=user.FullName%></span>
                            </div>
                            <div class="w3-col l3">
                                <span><%=cls.ClassName%></span>
                            </div>
                            <div class="w3-col l2">
                                <span class=" w3-text-grey">Chưa đóng</span>
                            </div>
                        </li>
                        <%
                              }
                          }
                        %>
                        <%} %>
                    </ul>
                </div>
            </div>
            <div class="w3-col l5 w3-padding-top w3-padding-right w3-padding-bottom w3-right">
                <div class="w3-white w3-card-2">
                    <header class="w3-padding w3-center w3-teal">
                        DANH SÁCH HỌC VIÊN ĐANG BẢO LƯU
                    </header>
                    <ul class="w3-ul">
                        <li class="w3-padding w3-row w3-light-grey">
                            <div class="w3-col l2">
                                <span>Mã HV</span>
                            </div>
                            <div class="w3-col l4">
                                <span>Họ tên</span>
                            </div>
                            <div class="w3-col l2">
                                <span>Lớp</span>
                            </div>
                            <div class="w3-col l2">
                                <span>Tiền</span>
                            </div>
                            <div class="w3-col l2">
                                <span>Thời hạn</span>
                            </div>
                        </li>
                    </ul>
                    <ul id="save_fee_area" class="save-fee w3-ul">
                        <%var get_save_fee = from p in new TblStudySaveFeeController().FetchAll() orderby p.Id descending select p;
                          foreach (TblStudySaveFee sf in get_save_fee)
                          {
                              var get_study = new TblUserController().FetchAll().Where(x => x.UserId == sf.UserId).Single();
                              var get_sf_class = new TblClassController().FetchAll().Where(x => x.Id == sf.ClassX);

                              DateTime now = DateTime.Now;
                              DateTime exp = DateTime.Parse(sf.SaveDate.ToString()).AddYears(+1);
                              TimeSpan remain = exp.Subtract(now);
                              int day = remain.Days;
                              if (day > 0)
                                  day++;      
                        %>
                        <li class="w3-padding w3-row">
                            <div class="w3-col l2">
                                <span><%=get_study.NumberStudy %></span>
                            </div>
                            <div class="w3-col l4">
                                <span><%=get_study.FullName %></span>
                            </div>
                            <div class="w3-col l2">
                                <%if (get_sf_class.ToList().Count != 0)
                                  { %>
                                <span><%=get_sf_class.Single().ClassName %></span>
                                <%} %>
                            </div>
                            <div class="w3-col l2">
                                <span><%=sf.DaysRemain %></span>
                            </div>
                            <%if (day > 14)
                              {%>
                            <div class="w3-col l2">
                                <span class=" w3-text-teal"><i class="fa fa-thumbs-o-up"></i>&nbsp;<%=day%> ngày</span>
                            </div>
                            <%}
                              else
                              { %>
                            <%if (day >= 7 && day <= 14)
                              { %>
                            <div class="w3-col l2">
                                <span class=" w3-text-orange"><i class="fa fa-exclamation-triangle"></i>&nbsp;<%=day%> ngày</span>
                            </div>
                            <%}
                              else
                              { %>
                            <div class="w3-col l2">
                                <span class=" w3-text-red"><i class="fa fa-times-circle"></i>&nbsp;<%=day%> ngày</span>
                            </div>
                            <%}
                                  }%>
                        </li>
                        <%} %>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
